package com.smile.f213;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MouseEventDemo {
	private JLabel label;
	public void createUI(){
		JFrame frame = new JFrame("鼠标事件处理示例");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		label = new JLabel();
		frame.add(label);
		frame.addMouseListener(new MouseHandler());
		frame.setSize(250, 120);
		frame.setVisible(true);
	}
	class MouseHandler implements MouseListener{
		@Override
		public void mouseClicked(MouseEvent e) {
			label.setText("执行了单击鼠标的动作");
		}
		@Override
		public void mouseEntered(MouseEvent e) {
			label.setText("鼠标进入监听区域");
		}
		@Override
		public void mouseExited(MouseEvent e) {
			label.setText("鼠标离开监听区域");
		}
		@Override
		public void mousePressed(MouseEvent e) {
			label.setText("执行了按下鼠标按键的动作");
		}
		@Override
		public void mouseReleased(MouseEvent e) {
			label.setText("执行了释放鼠标按键的动作");
		}
	}
	public static void main(String[] args) {
		MouseEventDemo mouseDemo = new MouseEventDemo();
		mouseDemo.createUI();
	}
}